package com.hjc.demo.clickhouse;

import okhttp3.*;

import java.io.IOException;

public class OkHttp3ClientUtil {

    static final OkHttpClient client = new OkHttpClient();
    public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");


    public static Response getData(String url, String param) throws IOException {
        RequestBody requestBody = RequestBody.create(JSON, param);
        Request request = new Request.Builder()
                .post(requestBody)
                .url(url)
                .build();
        return client.newCall(request).execute();
    }

    public static Response getDataByForm(String url, String param) throws IOException {
        FormBody.Builder builder = new FormBody.Builder();
        builder.add("query", param);
        Request request = new Request.Builder()
                .post(builder.build())
                .url(url)
                .build();
        return client.newCall(request).execute();
    }
}
